﻿/**
 FLVPlayerLiteController (AS3), version 1.0
 
 Enter description here
 
 <pre>
  ____                   _      ____ 
 |  __| _ __ ___    ___ | | __ |__  |
 | |   | '_ ` _ \  / __|| |/ /    | |
 | |   | | | | | || (__ | < | |
 | |__ |_| |_| |_| \___||_|\_\  __| |
 |____|                        |____|
 
 </pre>
 
 @class          :       FLVPlayerLiteController
 @author         :       Matthijs C. Kamstra [mck]
 @version        :       1.0 - class creation (AS3)
 @since          :       8-5-2008 14:47 
 
 
 
 NOTES:
         - this project is opensource: http://code.google.com/p/flvplayerlite/
         - some features descibed here will not be working currently so visit the project homepage for detailed information
         - visit my site: http://MatthijsKamstra.nl/blog
         - all your base are belong to us
         - will add 9KB to your .SWF (3,11 KB (3.185 bytes) from the FLVPlayerLite)
 
 CHANGELOG:
                 v 1.0 [2008-05-08] - Initial release
 
 */
 package nl.matthijskamstra.media {
         
		 
		 import com.ourbrander.webObj.component.easycomBobox;
         import flash.display.*;
         import flash.events.*;  
         import com.ourbrander.xmlObject.xmlFrame
		 import flash.geom.Rectangle;
		 import flash.events.MouseEvent
		 import flash.geom.Point
		 import flash.system.Capabilities;
		 import flash.geom.Rectangle;
	 	 import flash.display.Stage
	     import flash.display.StageDisplayState
		 
         public class FLVPlayerLiteController extends FLVPlayerLite {
                 
                 // Constants:
                 public static var CLASS_REF = nl.matthijskamstra.media.FLVPlayerLiteController;
                 public static var CLASS_NAME : String = "FLVPlayerLiteController";
                 public static var LINKAGE_ID : String = "nl.matthijskamstra.media.FLVPlayerLiteController";
				 public static const AUTOSIZE="autoSize"
                 
                 // var
                 private var FLVPlayerControler:Object;
                 private var _source:xmlFrame=new xmlFrame()  //data of the video list
				 private var _currentVideoIndex:uint//Index of the current video 
				 public var play_btn:MovieClip
				 private var xscale = 1
				 private var _combobox:easycomBobox
				 private var ConrolBarYposition:*
				 private var ConrolBarWidth:*
				 private var _videosizeW:uint=0
				 private var _videosizeH:uint = 0
				 private var _fullscreen:Function = null 
				 private var _init:Boolean=true
                 // vars
                 //UI,aready in the mc
				 //list_combobox 
				 //UI
                 /**
                 * Constructor: create a lite FLV player with controler
                 * 
                 * @usage        import nl.matthijskamstra.media.FLVPlayerLiteController; // import
                 *                       var __FLVPlayerLiteController:FLVPlayerLiteController = new FLVPlayerLiteController ( this , 'flv/Final_Mov_Sequence.flv' );
                 *                       (read comments in 'nl.matthijskamstra.media.FLVPlayerLite' & 'nl.matthijskamstra.media.FLVPlayerLiteController')
                 * 
                 * @param        $targetObj              a reference to a movie clip or object
                 * @param        $url                    path to FLV file (example: '../flv/foobar.flv')
                 * @param        $obj                    object with extra param (read mor about this in the comments on the top)
                 */
                 public function FLVPlayerLiteController( $targetObj:DisplayObjectContainer, $list:xmlFrame, $obj:Object = null) {
                         trace ( '+ ' + LINKAGE_ID + ' class instantiated');
						 source = $list
						 ConrolBarWidth =$obj.ConrolBarWidth
						 ConrolBarYposition = $obj.ConrolBarYposition
						 	
						 if ($obj.videosizeH != undefined && $obj.videosizeW != undefined) {
						
						 _videosizeW = uint($obj.videosizeW)
						 _videosizeH = uint($obj.videosizeH)
						 
						 }
						_fullscreen=($obj.fullscreen==undefined)?_fullscreen:$obj.fullscreen
						 var url = source.xml.child(0).link//set the first video
                         super($targetObj, url, $obj);
						 
						 currentVideoIndex = 1
						 play_btn = $obj. play_btn
						 $targetObj.visible=false
					    
						
						 
                 }
				 private function init() {
					
				 }
                 
                 /**
                  * 
                  */
				 public function updateControler(update_obj:Object=null) {
					 //------------------------------------------------------------------------------------------------------------------
					 
					 
						
					
					 if (update_obj!=null) {
						 var controlbarH = (update_obj.controlH == undefined)? -30:update_obj.controlH
						 var controlbarW=(update_obj.controlW == undefined)? 0:update_obj.controlW
					 }
					   
                         

						 var controlBar_width = (xscale + controlbarW) * videoObj_vid.width
						 trace(controlbarW)
						 var controlBar_height = videoObj_vid.height
						 FLVPlayerControler.y = videoObj_vid.height+controlbarH
					   
						 if (ConrolBarWidth==FLVPlayerLiteController.AUTOSIZE) {
							  FLVPlayerControler.bg_mc.width = controlBar_width - 1;
						 }
						 
						  if (String(ConrolBarWidth).indexOf("%") > 0) {
							  var tempw= String(ConrolBarWidth).substring(0, String(ConrolBarWidth).indexOf("%"))
							 
							 FLVPlayerControler.bg_mc.width = controlBar_width*(tempw/100)
						 }
						 FLVPlayerControler.x = Math.floor((videoObj_vid.width - FLVPlayerControler.bg_mc.width) * 0.5)
						
						 
                       
                        
                         play_btn.x = videoObj_vid.parent.x+( videoObj_vid.width - play_btn.width) * 0.5
						 play_btn.y=videoObj_vid.parent.y+(videoObj_vid.height-play_btn.height)*0.5
						// trace(videoObj_vid.parent+"}}}}}}}}}}}}}}}}}}}}"+videoObj_vid.parent.x+"vdieo:"+videoObj_vid.width+"play_btn"+play_btn.x)
						  if (_source.xml.child("*").length <= 1) {
							 FLVPlayerControler.list_combobox.x=FLVPlayerControler.bg_mc.width
							
						 }else {
							
							
						     FLVPlayerControler.list_combobox.x = FLVPlayerControler.bg_mc.width - 1 - FLVPlayerControler.list_combobox.width;
							 
						 }
						 
						 
						  
						  
                         FLVPlayerControler.soundBtn_mc.x = FLVPlayerControler.list_combobox.x - FLVPlayerControler.soundBtn_mc.width;
                         FLVPlayerControler.soundOffBtn_mc.x = FLVPlayerControler.list_combobox.x - FLVPlayerControler.soundOffBtn_mc.width;
						 FLVPlayerControler.volume_mc.x = FLVPlayerControler.list_combobox.x- FLVPlayerControler.volume_mc.width+5
                         
						 FLVPlayerControler.fullscreen_mc.x=FLVPlayerControler.volume_mc.x-FLVPlayerControler.fullscreen_mc.width-7
                         
                        // FLVPlayerControler.totalTime_txt.x = FLVPlayerControler.soundOffBtn_mc.x - FLVPlayerControler.totalTime_txt.width-10
						 //FLVPlayerControler.currentTime_txt.x = FLVPlayerControler.totalTime_txt.x - FLVPlayerControler.currentTime_txt.width 
						 
						 //hidden time show
                       
						 
						//FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.volume_mc.x - 10 - FLVPlayerControler.loaderSize_mc.x)
						 FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.fullscreen_mc.x - 10 - FLVPlayerControler.loaderSize_mc.x)
						
						 
						 
						 
                         //FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.currentTime_txt.x - 5 - FLVPlayerControler.loaderSize_mc.x)
						 FLVPlayerControler.loaderclick_mc.width=FLVPlayerControler.loaderSize_mc.width
                         FLVPlayerControler.loaderBar_mc.width = 0;
                         FLVPlayerControler.loaderProgress_mc.width = (FLVpercentLoaded / 100) * FLVPlayerControler.loaderSize_mc.width ;
                         
						 
						 
				  
					 
                       
					 //--------------------------------------------------------------------------------------------------------------------
				 }
                 private function setupControler () {
					 
					 trace("setupControler")
					  
                         //trace( "\t|\t " + CLASS_NAME + " :: setupControler  "  );
                         
                         FLVPlayerControler = targetObj.getChildByName ('flvControler_mc');
						
                         var FLVPlayerLite = targetObj.getChildByName ('FLVPlayerLite');
                         
                         if (FLVPlayerControler == null) {
                                 generateControler ();
                                 return;
                         }
                        if ( _videosizeW != 0&&_videosizeH!=0) {
						   	videoObj_vid.width = _videosizeW
							videoObj_vid.height=_videosizeH
						}
                       targetObj.swapChildren(FLVPlayerControler as DisplayObject,FLVPlayerLite as DisplayObject);
					  //    targetObj.swapChildren(FLVPlayerLite as DisplayObject,FLVPlayerControler as DisplayObject);
                         
                         // get original width from loader
                         
                         // position is defined when the size of the movie is known (onMetaDataListener)
						 var controlBar_width = xscale*videoObj_vid.width
						 var controlBar_height = videoObj_vid.height
						 
						 if (ConrolBarYposition==FLVPlayerLiteController.AUTOSIZE) {
							  FLVPlayerControler.y = controlBar_height
						 }
						 
						  if (String(ConrolBarYposition).indexOf("%") > 0) {
							  var tempy= String(ConrolBarYposition).substring(0, String(ConrolBarYposition).indexOf("%"))
							 // trace("tempy>>>>>>>>>"+tempy)
							  FLVPlayerControler.y = controlBar_height*(tempy/100)
						 }
						 
						 if (ConrolBarWidth==FLVPlayerLiteController.AUTOSIZE) {
							  FLVPlayerControler.bg_mc.width = controlBar_width - 1;
						 }
						 
						  if (String(ConrolBarWidth).indexOf("%") > 0) {
							  var tempw= String(ConrolBarWidth).substring(0, String(ConrolBarWidth).indexOf("%"))
							 
							 FLVPlayerControler.bg_mc.width = controlBar_width*(tempw/100)
						 }
						 FLVPlayerControler.x = Math.floor((videoObj_vid.width - FLVPlayerControler.bg_mc.width) * 0.5)
						
						 if ( targetObj.parent.getChildByName("prevideo_mc")!=null) {
							  var prevideo_mc = targetObj.parent.getChildByName("prevideo_mc")
							   prevideo_mc.visible=false
						 }
						 targetObj.visible=true
						 //---------------------------------------------------------
						//trace(controlBar_width)
						 
                       
                        
                         play_btn.x = videoObj_vid.parent.x+( videoObj_vid.width - play_btn.width) * 0.5
						 play_btn.y=videoObj_vid.parent.y+(videoObj_vid.height-play_btn.height)*0.5
						// trace(videoObj_vid.parent+"}}}}}}}}}}}}}}}}}}}}"+videoObj_vid.parent.x+"vdieo:"+videoObj_vid.width+"play_btn"+play_btn.x)
						 FLVPlayerControler.parent.setChildIndex(FLVPlayerControler, 2)
						 
						 if (_source.xml.child("*").length <= 1) {
							 FLVPlayerControler.list_combobox.x=FLVPlayerControler.bg_mc.width
							FLVPlayerControler.list_combobox.visible = false
							// trace(FLVPlayerControler.list_combobox.visible)
							//FLVPlayerControler.list_combobox.width=1
							//FLVPlayerControler.list_combobox.x = controlBar_width - 1 - FLVPlayerControler.list_combobox.width;
 
						 }else {
							// trace("only one video"+FLVPlayerControler.list_combobox.length)
							 FLVPlayerControler.list_combobox.visible = true 
							
						     FLVPlayerControler.list_combobox.x = FLVPlayerControler.bg_mc.width - 1 - FLVPlayerControler.list_combobox.width;
							 initCombobox(FLVPlayerControler.list_combobox)
						 }
						 
						  
						  
                         FLVPlayerControler.soundBtn_mc.x = FLVPlayerControler.list_combobox.x - FLVPlayerControler.soundBtn_mc.width;
                         FLVPlayerControler.soundOffBtn_mc.x = FLVPlayerControler.list_combobox.x - FLVPlayerControler.soundOffBtn_mc.width;
						 FLVPlayerControler.volume_mc.x = FLVPlayerControler.list_combobox.x- FLVPlayerControler.volume_mc.width+5
                         
						 FLVPlayerControler.fullscreen_mc.x=FLVPlayerControler.volume_mc.x-FLVPlayerControler.fullscreen_mc.width-7
                         
                        // FLVPlayerControler.totalTime_txt.x = FLVPlayerControler.soundOffBtn_mc.x - FLVPlayerControler.totalTime_txt.width-10
						 //FLVPlayerControler.currentTime_txt.x = FLVPlayerControler.totalTime_txt.x - FLVPlayerControler.currentTime_txt.width 
						 
						 //hidden time show
                         FLVPlayerControler.totalTime_txt.visible = FLVPlayerControler.currentTime_txt.visible = false
						 
						//FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.volume_mc.x - 10 - FLVPlayerControler.loaderSize_mc.x)
						 FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.fullscreen_mc.x - 10 - FLVPlayerControler.loaderSize_mc.x)
						
						 
						 
						 
                         //FLVPlayerControler.loaderSize_mc.width = Math.floor(FLVPlayerControler.currentTime_txt.x - 5 - FLVPlayerControler.loaderSize_mc.x)
						 FLVPlayerControler.loaderclick_mc.width=FLVPlayerControler.loaderSize_mc.width
                         FLVPlayerControler.loaderBar_mc.width = 0;
                         FLVPlayerControler.loaderProgress_mc.width = (FLVpercentLoaded / 100) * FLVPlayerControler.loaderSize_mc.width ;
                         FLVPlayerControler.playHead_mc.isDraging=false// this attributes can control the playHead_mc's x
						 FLVPlayerControler.playHead_mc.buttonMode=true
						 
						 
						 //play or puase-------------------------------------
						  FLVPlayerControler.playBtn_mc.addEventListener(MouseEvent.CLICK, vControl)
						  FLVPlayerControler.pauseBtn_mc.addEventListener(MouseEvent.CLICK,vControl)
						  FLVPlayerControler.playBtn_mc.buttonMode=FLVPlayerControler.pauseBtn_mc.buttonMode=true
						  play_btn.buttonMode=true
				          play_btn.addEventListener(MouseEvent.CLICK, vControl )
				
					 
						 //play or puase end------
						 
						 //fullscrenn listener
						 FLVPlayerControler.fullscreen_mc.buttonMode=true
						 FLVPlayerControler.fullscreen_mc.addEventListener(MouseEvent.CLICK, toggleFullScreen)
						 
						 //drag seek --------------------------------
						 FLVPlayerControler.loaderclick_mc.addEventListener(MouseEvent.MOUSE_DOWN, bgclicked)
						 
						 
						 FLVPlayerControler.playHead_mc.addEventListener(MouseEvent.MOUSE_DOWN, DragVideoSeekbar)
						 FLVPlayerControler.playHead_mc.addEventListener(MouseEvent.ROLL_OUT, playheadRollOut )
						 FLVPlayerControler.stage.addEventListener(MouseEvent.MOUSE_UP, stopDragVideoSeekbar)
						 FLVPlayerControler.playHead_mc.addEventListener(MouseEvent.ROLL_OVER, function(e = null) { FLVPlayerControler.playHead_mc.alpha = 1;  FLVPlayerControler.playHead_mc.gotoAndStop(2)} )
						 
						 //drag seek---------------------------------
						 
						 // volume control ----------------------------------------------
                         var volume_drag:MovieClip = FLVPlayerControler.volume_mc.volume_drag
						 volume_drag.buttonMode=true
						 volume_drag.addEventListener(MouseEvent.MOUSE_DOWN, DragVolumebar)
						  FLVPlayerControler.parent.addEventListener(MouseEvent.MOUSE_UP,stopDragVolumebar)
					
                         // setup controlers
                         //FLVPlayerLiteControllerButton.onRelease (FLVPlayerControler.playBtn_mc , buttonActivateButton, 'play');
                        // FLVPlayerLiteControllerButton.onRelease (FLVPlayerControler.pauseBtn_mc , buttonActivateButton, 'pause');
                         //FLVPlayerLiteControllerButton.onRelease (FLVPlayerControler.soundBtn_mc , buttonActivateButton, 'playSound');
                        // FLVPlayerLiteControllerButton.onRelease (FLVPlayerControler.soundOffBtn_mc , buttonActivateButton, 'stopSound');
                         
                         //FLVPlayerLiteControllerButton.onRollover (FLVPlayerControler.playBtn_mc , buttonActivateButton, 'rolloverPlay');
                        // FLVPlayerLiteControllerButton.onRollover (FLVPlayerControler.pauseBtn_mc , buttonActivateButton, 'rolloverPause');                      
                         //FLVPlayerLiteControllerButton.onRollover (FLVPlayerControler.soundBtn_mc , buttonActivateButton, 'rolloverPlaySound');
                         //FLVPlayerLiteControllerButton.onRollover (FLVPlayerControler.soundOffBtn_mc , buttonActivateButton, 'rolloverStopSound');                       
                         
                          trace( "isAutostart: " + isAutostart);
                         if (isAutostart) {
                                 FLVPlayerControler.playBtn_mc.visible = false;
								   
                         }
						 if(isPlaying==false) {
							  FLVPlayerControler.playBtn_mc.visible = true
							
							 puaseVideo()
						 }
						
                         if (isSoundOnStart) {
                                 FLVPlayerControler.soundBtn_mc.visible = true;
                         }
                         
                         /*      
                         |        0.      name:size_mc    type:object    [object MovieClip]
                         |        1.      name:bg_mc      type:object    [object MovieClip]
                         |        2.      name:loaderSize_mc      type:object    [object MovieClip]
                         |        3.      name:loaderProgress_mc  type:object    [object MovieClip]
                         |        4.      name:loaderBar_mc       type:object    [object MovieClip]
                         |        5.      name:currentTime_txt    type:object    [object TextField]
                         |        6.      name:totalTime_txt      type:object    [object TextField]
                         |        7.      name:soundOffBtn_mc     type:object    [object soundOffBtn_mc_5]
                         |        8.      name:soundBtn_mc        type:object    [object soundBtn_mc_6]
                         |        9.      name:pauseBtn_mc        type:object    [object pauseBtn_mc_7]
                         |        10.     name:playBtn_mc         type:object    [object playBtn_mc_8]
                         */
                         //this is a addtional function,show a video list in the controlPanel
						 FLVPlayerControler.visible=true
                         trace( ">>>>>>>>>>>>"+FLVPlayerControler.playBtn_mc.visible)
                         
                 }
                 
                 private function generateControler():void{
                         trace (':: no FLVPlayerControler, so it needs to be generated >> doesn\'t work yet')
                 }
                 	/*private function initCombobox(taret) {
						combobox = new easycomBobox()
						combobox.setInterface(taret)
						combobox.x = taret.x
						combobox.y = taret.y
						combobox.setData(source, "title")
						addChild(combobox)
						//addEventListener(easycomBobox.SELECTED_CHANGE,changeVideo_bridge)
					}
					*/
                 private function buttonActivateButton($id:String):void {
                         //trace( "++ buttonActivateButton : " + buttonActivateButton );
                         //trace( "$id : " + $id );
                         switch ($id) {
                                 case 'play': 
                                         //trace('play');
                                         playMedia();
                                         FLVPlayerControler.playBtn_mc.visible = false;
                                         break;
                                 case 'pause': 
                                         //trace('pause');
                                         pauseMedia();
                                         FLVPlayerControler.playBtn_mc.visible = true;
                                         break;
                                 case 'playSound': 
                                         //trace('playSound');
                                         mute();
                                         FLVPlayerControler.soundBtn_mc.visible = false;
                                         break;
                                 case 'stopSound': 
                                         //trace('stopSound');
                                         mute();
                                         FLVPlayerControler.soundBtn_mc.visible = true;
                                         break;
                                 case 'rolloverPause': 
                                         //trace('rolloverPause');
                                         break;
                                 case 'rolloverPlay': 
                                         //trace('rolloverPlay');
                                         break;
                                 case 'rolloverStopSound': 
                                         //trace('rolloverStopSound');
                                         break;
                                 case 'rolloverPlaySound': 
                                         //trace('rolloverPlaySound');
                                         break;
                                 default:
                                         trace( "case '" + $id + "': \n\ttrace('"+$id+"');\n\tbreak;");
                         }
                         
                 }
                 
         
                 ////////////////////////////////// start: FLV loading ///////////////////////////////////
                 
                 override public function onLoadProgress($percent:Number):void {
                         //trace( "\t|\t " + CLASS_NAME + " :: onLoadProgress -- $percent : " + $percent );
                         if (FLVPlayerControler != null) {
                                 FLVPlayerControler.loaderProgress_mc.width = ($percent / 100) * FLVPlayerControler.loaderSize_mc.width;
                         }
                 }
                 
                 ////////////////////////////////// end: FLV loading ///////////////////////////////////
                 
                 ////////////////////////////////// start: FLV playhead ///////////////////////////////////
                 
                 override public function onPlayProgress($percent:Number, $currentTime:Number, $totalTime:Number):void {
                         //trace( "\t|\t " + CLASS_NAME + " :: onPlayProgress -- $percent : " + $percent + " | $currentTime : " + $currentTime + " | $totalTime : " + $totalTime );
                         if (FLVPlayerControler != null) {
                                 FLVPlayerControler.loaderBar_mc.width = ($percent / 100) * FLVPlayerControler.loaderSize_mc.width;
                                 FLVPlayerControler.currentTime_txt.text = timeNotation ($currentTime);
                                 FLVPlayerControler.totalTime_txt.text = timeNotation ($totalTime);
								 
								 if (!FLVPlayerControler.playHead_mc.isDraging) {
									 FLVPlayerControler.playHead_mc.x= FLVPlayerControler.loaderBar_mc.x+ FLVPlayerControler.loaderBar_mc.width-FLVPlayerControler.playHead_mc.width
								 }
								 if ( FLVPlayerControler.playHead_mc.x<FLVPlayerControler.loaderSize_mc.x) {
									 FLVPlayerControler.playHead_mc.visible=false
								 }else {
								    FLVPlayerControler.playHead_mc.visible=true
								 }
								 
                         }
                 }
                 
                 ////////////////////////////////// end: FLV playhead ///////////////////////////////////
                 
                 private function timeNotation ($sec:Number):String {
                         var minutes = Math.floor ($sec / 60);
                         var seconds = Math.floor ($sec % 60);
                         if (minutes < 10) { minutes = "0" + minutes; }
                         if (seconds < 10) { seconds = "0" + seconds; }
                         return (minutes + ":" + seconds);
                 }
                 
                 /////////////////////////////////////// Static ///////////////////////////////////////
                 
                 /**
                 * create a lite FLV player with controler
                 * 
                 * @usage        import nl.matthijskamstra.media.FLVPlayerLiteController; // import
                 *                       FLVPlayerLiteController.create ( this , 'flv/Final_Mov_Sequence.flv' );
                 *                       (read comments in 'nl.matthijskamstra.media.FLVPlayerLite' & 'nl.matthijskamstra.media.FLVPlayerLiteController')
                 * 
                 * @param        $targetObj              a reference to a movie clip or object
                 * @param        $url                    path to FLV file (example: '../flv/foobar.flv')
                 * @param        $obj                    object with extra param (read mor about this in the comments on the top)
                 */
                 public static function create ( $targetObj:DisplayObjectContainer , $list:xmlFrame, $obj:Object = null):FLVPlayerLite {
					 /*added by liuyi 2009.2.26*/
                       
					 
					 
					 /*added by liuyi 2009.2.26*/
                       return new FLVPlayerLiteController ($targetObj, $list , $obj);
                 }
                 
                 //////////////////////////////////////// Listener ////////////////////////////////////////
                 
                 
                 override public function onMetaDataListener(info:Object):void {
                         //trace( "onMetaDataListener : " + onMetaDataListener );
                         // for( var i:String in info ) //trace( "key : " + i + ", value : " + info[ i ] );
                         
                         // data used by FLVPlayerLite
                         nDuration = info.duration;      
                         
                         var vidWidth:Number     = info.width;
                         var vidHeight:Number    = info.height;
                         
                         videoObj_vid.width              = vidWidth;
                         videoObj_vid.height     = vidHeight;
                         
                         // extra data by the FLVPlayerLiteController
                         setupControler ();
                         
                 }
                 
				 /*added function by liuyi 2009.2.26-------------*/
				 public function set source($xml) {
				 _source = $xml
				
				 }
                 
				 public  function get source() :xmlFrame{
					 return _source 
				 }
				 
				 
				 public  function set currentVideoIndex(num:uint) {
					_currentVideoIndex =num
				 }
				 public  function get currentVideoIndex():uint {
					return _currentVideoIndex 
				 }
				 private function initCombobox(target) {
					 if (_combobox==null) {
					 _combobox=new easycomBobox ()
					 }
					
					//_combobox.selectedItem
					_combobox.setInterface(target)
					_combobox.x = target.x
					_combobox.y = target.y
					
					_combobox.setData(source, "title")
					FLVPlayerControler.addChild(_combobox)
					 
					_combobox.addEventListener(easycomBobox.SELECTED_CHANGE, changeVideo_bridge)
				      
					 
					 
					FLVPlayerControler.parent.setChildIndex(FLVPlayerControler, 2)
					trace("0:::" + FLVPlayerControler.parent.getChildAt(0))
					trace("1:::" + FLVPlayerControler.parent.getChildAt(1))
					trace("2:::"+FLVPlayerControler.parent.getChildAt(2))
					
					if(isPlaying==false){
					FLVPlayerControler.playBtn_mc.visible = true
					}
					
				 }
				 private function changeVideo_bridge(e) {
					 
					 var $url = _source.xml.child(e.content.index).link
					 trace($url)
					 changeVideo($url)
					 FLVPlayerControler.parent.setChildIndex(FLVPlayerControler, 2)
					 
					trace("event0:::" + FLVPlayerControler.parent.getChildAt(0))
					trace("event1:::" + FLVPlayerControler.parent.getChildAt(1))
					trace("event2:::"+FLVPlayerControler.parent.getChildAt(2))
					 
				 }
				 override public function rewToStartAndStop():void  {
								  nsVideo.seek(0);
								  if (isPlaying=true) {
									 stopMedia()  
								  }
								 
								  FLVPlayerControler.pauseBtn_mc.visible = false
								  play_btn.visible = true
								  play_btn.alpha=1
								  FLVPlayerControler.playBtn_mc.visible = true
								  trace( "FLVPlayerControler.playBtn_mc.visible:"+FLVPlayerControler.playBtn_mc.visible)
								  
				
				 }
				 
				 public function  vControl(e = null) {
							 if(e.currentTarget==FLVPlayerControler.playBtn_mc||e.currentTarget==play_btn){  
							      FLVPlayerControler.playBtn_mc.visible = false
								  play_btn.visible = false
								  play_btn.alpha=0
								  FLVPlayerControler.pauseBtn_mc.visible = true
								  playMedia();
								  trace("vvvv start play()")
							 }else if (e.currentTarget ==FLVPlayerControler.pauseBtn_mc) {
								  FLVPlayerControler.pauseBtn_mc.visible = false
								  play_btn.visible = false
								  play_btn.alpha=0
								  FLVPlayerControler.playBtn_mc.visible = true
								  pauseMedia()
								   trace(".....stop play()")
							 } 
							 // playPauseToggle()
				}
				
				public function playVideo() {
							      FLVPlayerControler.pauseBtn_mc.visible = true
								  play_btn.visible = false
								  play_btn.alpha=0
								  FLVPlayerControler.playBtn_mc.visible = false
								  trace("isPlaying"+isPlaying)
								  if (isPlaying==false) {
									  trace("pppllllaaayyyy")
									   playMedia() 
								  }
								   
								  
				}
				
				public function puaseVideo() {
							      FLVPlayerControler.pauseBtn_mc.visible = false
								  play_btn.visible = false
								  play_btn.alpha=0
								  FLVPlayerControler.playBtn_mc.visible = true
								  trace("isPlaying:"+isPlaying)
								  if (isPlaying==true) {
									  trace("s....t.....o.....p.")
									   pauseMedia() 
									  
								  }
								  if(isAutostart==false && _init==true){
									nsVideo.seek(1)
									_init==false
								  }
								  trace("stop play().....")
				}
				 /*added function by liuyi 2009.2.26 end-----------------*/
				 
				 
				 
				 				 // volume control ----------------------------------------------
                     
						
						 
						 
						function DragVolumebar(e:MouseEvent) {
							 var volume_msk = FLVPlayerControler.volume_mc.volume_mask
							 var volume_drag:MovieClip = FLVPlayerControler.volume_mc.volume_drag
							 var rectangle=new Rectangle(-(FLVPlayerControler.volume_mc.volume_mask.width),0,FLVPlayerControler.volume_mc.volume_mask.width,0)
							 volume_drag.startDrag(false, rectangle)
							 volume_drag.addEventListener(Event.ENTER_FRAME,setVolume)
							 
							 
							 
						 }
						 
						 function setVolume(e=null) {
							  var volume_drag:MovieClip = FLVPlayerControler.volume_mc.volume_drag
							  var volume_drag_show:MovieClip = FLVPlayerControler.volume_mc.volume_drag_show
							  var volume_msk = FLVPlayerControler.volume_mc.volume_mask
							  volume_drag_show.x = volume_drag.x
							  var tempVolume = ((volume_msk.width+volume_drag.x) / volume_msk.width) 
							  Volume = tempVolume
							    
							  
						 }
						 
						 function stopDragVolumebar(e) {
							 
							   var volume_drag:MovieClip = FLVPlayerControler.volume_mc.volume_drag
							   volume_drag.stopDrag()	
							   
						 }
						 
						 // volume control end ----------------------------------------------
						 //drag----
						 function DragVideoSeekbar(e = null) {
							   FLVPlayerControler.playHead_mc.isDraging=true 
							  var rectangle = new Rectangle( (FLVPlayerControler.loaderSize_mc.x), FLVPlayerControler.playHead_mc.y, FLVPlayerControler.loaderSize_mc.width- FLVPlayerControler.playHead_mc.width, 0)
							  
							  FLVPlayerControler.playHead_mc.startDrag(false,rectangle)
						 }
						 function stopDragVideoSeekbar(e = null) {
							 if (FLVPlayerControler.playHead_mc.isDraging != true) {
								 return false
							 }
							 FLVPlayerControler.playHead_mc.isDraging = false
							  FLVPlayerControler.playHead_mc.alpha = 0.5
							  FLVPlayerControler.playHead_mc.gotoAndStop(1)
							 var percent = ((FLVPlayerControler.playHead_mc.width + FLVPlayerControler.playHead_mc.x - FLVPlayerControler.loaderSize_mc.x) / FLVPlayerControler.loaderSize_mc.width)*nDuration 
							 //trace(FLVPlayerControler.playHead_mc.x+"/"+FLVPlayerControler.loaderSize_mc.width+"/"+FLVPlayerControler.playHead_mc.width+"/"+FLVPlayerControler.loaderSize_mc.x)
							  
							 seek(percent)
							 
							 
						 }
						 
						 	 function playheadRollOut (e = null) {
							  if (FLVPlayerControler.playHead_mc.isDraging != true) {
								 FLVPlayerControler.playHead_mc.gotoAndStop(1)
								 FLVPlayerControler.playHead_mc.alpha=0.5
							 }
						     
						 }
						 
						 function bgclicked(e = null) {
							// var clickPoint:Point = new Point(e.currentTarget.mouseX, e.currentTarget.mouseY);
                           // trace( e.currentTarget.mouseX+"/"+e.currentTarget.width)
							// trace(e.currentTarget.localToGlobal(clickPoint))
							 // trace(FLVPlayerControler.loaderSize_mc.x)
						 }
						 
						 //drag end
		private function fullClickHandler(e:MouseEvent):void{
			
			//var maxWidth:int = Capabilities.screenResolutionX;
			//var maxHeight:int = Capabilities.screenResolutionY;
		//	var diffHeight:int = (stage.stageHeight - maxHeight)/2;
			
			//stage.fullScreenSourceRect = new Rectangle(0, diffHeight, stage.stageWidth, (maxHeight - diffHeight));
			stage.displayState = StageDisplayState.FULL_SCREEN;
			
		}
		public function toggleFullScreen(event=null) {
				 _fullscreen(event)
			  
        }  

    } // end class
         
 } // end package
 